<template>
  <div class="app-container">
    <div class="view-title">宽带订单</div>

    <el-table :data="tableDataBoradOrder" style="width: 100%">
      <el-table-column prop="id" label="id"> </el-table-column>
      <el-table-column prop="order_no" label="订单号" width="130">
      </el-table-column>
      <el-table-column prop="package_name" label="套餐" width="130">
        <template slot-scope="scope">{{
          scope.row.package_name ? scope.row.package_name : ""
        }}</template>
      </el-table-column>
      <el-table-column prop="out_package_id" label="套餐编码">
      </el-table-column>
      <el-table-column prop="api_order_no" label="运营商单号" width="130">
      </el-table-column>

      <el-table-column prop="open_status" label="受理状态">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.open_status == 0">
            {{ scope.row.open_status | getOpenStatus }}</el-tag
          >

          <el-tag type="warning" v-else-if="scope.row.open_status == 1">
            {{ scope.row.open_status | getOpenStatus }}</el-tag
          >

          <el-tag type="success" v-else-if="scope.row.open_status == 2">
            {{ scope.row.open_status | getOpenStatus }}</el-tag
          >

          <el-tag type="danger" v-else-if="scope.row.open_status == 3">
            {{ scope.row.open_status | getOpenStatus }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column
        prop="open_message"
        label="受理回文"
        :show-overflow-tooltip="true"
        width="150"
      >
      </el-table-column>
      <el-table-column prop="user_id" label="用户id" width="120">
      </el-table-column>
      <el-table-column prop="id_card_name" label="身份证姓名">
      </el-table-column>
      <el-table-column prop="id_card" label="身份证号"> </el-table-column>
      <el-table-column prop="contact" label="联系人姓名"> </el-table-column>
      <el-table-column prop="mobile" label="联系电话"> </el-table-column>
      <el-table-column prop="express_address" label="收货地址" width="180">
      </el-table-column>

      <el-table-column prop="src" label="订单来源" width="130">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.src == 0">落地页</el-tag>
          <el-tag type="warning" v-else-if="scope.row.src == 1">小程序</el-tag>
          <el-tag type="primary" v-else-if="scope.row.src == 2"
            >抖音直播</el-tag
          >
          <el-tag type="info" v-else-if="scope.row.src == 3">接口提单</el-tag>
          <el-tag type="danger" v-else-if="scope.row.src == 4">抖音提单</el-tag>
          <el-tag type="danger" v-else-if="scope.row.src == 5"
            >抖音直播提单</el-tag
          >
        </template>
      </el-table-column>

      <el-table-column prop="active_status" label="激活状态">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.active_status == 0"
            >未激活</el-tag
          >
          <el-tag type="warning" v-else>已激活</el-tag>
        </template>
      </el-table-column>

      <el-table-column prop="active_time" label="激活时间"> </el-table-column>

      <el-table-column prop="created_at" fixed="right" label="创建时间">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)" type="text" size="small"
            >编辑</el-button
          >
          <el-button @click="handleDelete(scope.row)" type="text" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="page_box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryParams.pageNow"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 编辑 -->
    <edit-broad-order
      ref="refEditBroadOrder"
      :editDetails="editDetails"
      @sureEdit="sureEdit"
      @cancelEdit="cancelEdit"
    />
  </div>
</template>
<script>
import {
  getAppKdorderList,
  deleteAppKdorder,
  updateAppKdorder,
  getAppKdorderInfo,
} from "@/api/broadOrder";
import EditBroadOrder from "./components/editBroadOrder.vue";
export default {
  components: {
    EditBroadOrder,
  },
  data() {
    return {
      tableDataBoradOrder: [],
      queryParams: {
        pageNow: 1,
        pageSize: 10,
      },
      total: null,
      editDetails: {},
    };
  },
  filters: {
    getOpenStatus(val) {
      if (val == 0) {
        return (val = "待受理");
      } else if (val == 1) {
        return (val = "受理中");
      } else if (val == 2) {
        return (val = "受理成功");
      } else if (val == 3) {
        return (val = "受理失败");
      }
    },
  },
  mounted() {
    this.getAppKdorderList();
  },
  methods: {
    // 获取宽带订单列表接口
    getAppKdorderList() {
      getAppKdorderList({
        page_now: this.queryParams.pageNow,
        page_size: this.queryParams.pageSize,
      }).then((res) => {
        if (res.code == 1) {
          this.tableDataBoradOrder = res.data;
          this.total = res.page_info.total_count;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 删除订单接口
    deleteAppKdorder(val) {
      deleteAppKdorder({
        ids: val,
      }).then((res) => {
        if (res.code == 1) {
          this.$message.success("删除成功");
          this.getAppKdorderList();
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 查询单条接口
    getAppKdorderInfo(val) {
      getAppKdorderInfo({
        id: val,
      }).then((res) => {
        if (res.code == 1) {
          this.editDetails = res.data;
          this.$refs.refEditBroadOrder.dialogVisibleEdit = true;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 编辑接口
    updateAppKdorder(val) {
      updateAppKdorder({
        id: val.id,
        id_card_name: val.id_card_name,
        id_card: val.id_card,
        express_address: val.express_address,
        mobile: val.mobile,
        contact: val.contact,
      }).then((res) => {
        if (res.code == 1) {
          this.$message.success("编辑成功");
          this.$refs.refEditBroadOrder.dialogVisibleEdit = false;
          this.getAppKdorderList();
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 编辑
    handleEdit(val) {
      this.getAppKdorderInfo(val.id);
    },

    // 编辑确定
    sureEdit(val) {
      this.updateAppKdorder(val);
    },

    // 编辑取消
    cancelEdit(val) {
      this.$refs.refEditBroadOrder.dialogVisibleEdit = false;
    },

    // 删除
    handleDelete(val) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteAppKdorder(val.id);
        })
        .catch(() => {});
    },

    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.queryParams.pageNow = 1;
      this.getAppKdorderList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageSize = 10;
      this.queryParams.pageNow = val;
      this.getAppKdorderList();
    },
  },
};
</script>
<style lang="scss" scoped></style>
